package ru.ifmo;

/**
 * Created by Admin on 02.02.15.
 */
public class Item {
    private float redComponent = 0.0f;
    private float greenComponent = 0.0f;
    private float blueComponent = 0.0f;
    private int normalizeCount = 0;

    public Item() {

    }

    public void increaseComponents(double red, double green, double blue) {
        redComponent += red;
        greenComponent += green;
        blueComponent += blue;
        normalizeCount++;
    }

    public float getNormalizedRedComponent() {
        return redComponent / normalizeCount;
    }

    public float getNormalizedGreenComponent() {
        return greenComponent / normalizeCount;
    }

    public float getNormalizedBlueComponent() {
        return blueComponent / normalizeCount;
    }

    public String getColor() {
        float red = getNormalizedRedComponent();
        float green = getNormalizedGreenComponent();
        float blue = getNormalizedBlueComponent();

        if (red > blue && red > green) {
            return "Red";
        } else if (green > red && green > blue) {
            return "Green";
        } else if (Math.abs(green - blue) <= 0.25 && green > red && blue > red) {
            return "Blue"; // да-да, вот такой у нас странный синий. Датчик определяет синий цвет как совокупность синей и зеленой компоненты
        } else return "Unknown";
    }
}
